package com.llkj.qingnianguoxue.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.JingXuanBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;
import com.xiaweizi.cornerslibrary.CornersProperty;

import java.util.List;

/**
 * 首页——课程和活动
 */
public class HomeJXActionAdapter extends BaseQuickAdapter<JingXuanBean,BaseViewHolder> {
    private int type = 1;//1课程，2活动

    public HomeJXActionAdapter(int layoutResId, List<JingXuanBean> data) {
        super(layoutResId, data);
    }

    @Override
    public int getItemCount() {
        int count = 0;
        if(mData!=null){
                count = mData.size()>2?2:mData.size();
        }
        return count;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, JingXuanBean item) {
        ImageView ivPic = (ImageView) baseViewHolder.getView(R.id.iv_action_pic);
        TextView tvTitle = (TextView) baseViewHolder.getView(R.id.tv_title);
        tvTitle.setText(item.getName());
        tvTitle.setTextSize(14);
        tvTitle.setMaxLines(1);
        tvTitle.setEllipsize(TextUtils.TruncateAt.END);
        TextView tvAdress = (TextView) baseViewHolder.getView(R.id.tv_address);
        tvAdress.setText(item.getSite());

        String money = "￥" + item.getPrice();
        TextView tvPrice = (TextView) baseViewHolder.getView(R.id.tv_money);
        tvPrice.setText(money);

        TextView tvState = (TextView) baseViewHolder.getView(R.id.tv_state);//预约状态
        boolean isReserve = "1".equals(item.getIs_reserve())?true:false;
        tvState.setSelected(isReserve);

        LinearLayout.LayoutParams picParams = (LinearLayout.LayoutParams) ivPic.getLayoutParams();
        picParams.width = (DisplayUtil.getDensityWdith(mContext)-DisplayUtil.dip2px(mContext, 40))/2;
        picParams.height = picParams.width/2;

        LinearLayout llRoot = baseViewHolder.getView(R.id.ll_root);
        LinearLayout.LayoutParams rootParams = (LinearLayout.LayoutParams) llRoot.getLayoutParams();
        rootParams.width = picParams.width;
        ImageLoadingUtil.loadImgGlideRound(ivPic, item.getActivityimg(),
                5, CornersProperty.CornerType.TOP);
    }

    public void setType(int type1){
        type = type1;
    }
}
